package org.grill.clovercash.accounts;

import java.math.BigDecimal;

public class SumRangeFinder {

	public int[] find(BigDecimal target, BigDecimal[] decimals) {

		for (int currStart = 0; currStart < decimals.length; currStart++) {
			for (int currEnd = decimals.length-1; currEnd >= currStart; currEnd--) {
				BigDecimal total = new BigDecimal(0);
				for (int i = currStart; i <= currEnd; i++) {
					total = total.add(decimals[i]);
				}
				if (total.subtract(target).abs().floatValue() < 1.0)
					System.out.println("Difference; " + total.subtract(target));
				if (total.equals(target)) {
					return new int[] {currStart, currEnd}; 
				}
			}
		}
		
		return new int[] {-1,-1};
	}

}
